<template>
  <div>
    <full-dialog :isShow.sync="dialog_state" @close="init" @confirm="submit" title="新增文章" width="600">
      <div class="full-dialog-private">
        <div class="form">
          <el-form ref="form" :model="form_data" label-width="100px" label-position="left">
            <el-form-item label="文章标题">
              <el-input size="mini" v-model="form_data.title" placeholder="请输入文章标题"></el-input>
            </el-form-item>
            <el-form-item label="关键字">
              <el-input size="mini" v-model="form_data.keyword" placeholder="请输入文章关键字"></el-input>
            </el-form-item>
            <el-form-item label="内容">
              <!-- <div id="ueditor" type="text/plain"></div> -->
              <el-input type="textarea" size="mini" v-model="form_data.content" placeholder="请输入文章内容"></el-input>
            </el-form-item>
            <el-form-item label="文章类型">
              <el-select size="mini" v-model="form_data.articleType" placeholder="请选择">
                <el-option v-for="item in typeList" :key="item.typeId" :label="item.typeName" :value="item.typeId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </full-dialog>
  </div>
</template>
<script>
import handle_mixin from "@/mixin/handle-mixin";
import request from "@/utils/request";
export default {
  mixins: [handle_mixin],
  props: ['obj'],
  data() {
    return {
      dialog_state: false,
      title: "",
      keyword: "",
      ue: "",
      content: "",
      lastTime: "",
      addTime: "",
      articleId: "",
      dataObject: "",
      form_data: {
        title: "",
        keyword: "",
        content: "",
        articleType: ""
      },
      typeList: []
    }
  },
  watch: {
    dialog_state(val, oldVal) {
      console.log(this.obj)
      if (val) {
        this.form_data = this.obj;
        this.getArticleType();
      }
    }
  },
  methods: {
    getArticleType() {
      request({
        url: "/api/article/getArticleTypeList",
        method: "post",
        data: {}
      }).then(res => {
        console.log(res);
        if (res.msg === "查询成功") {
          this.typeList = res.list;
        }
      });
    },
    open_dialog(data) {
      this.dialog_state = true;
    },
    submit(resonse) {
      request({
        url: "/api/article/updateArticle",
        method: "post",
        data: this.form_data
      }).then(res => {
        console.log(res);
        if (res.msg === "修改成功") {
          this.$message({
            message: "修改成功！",
            type: "success"
          });
          this.dialog_state = false;
        }
      });
    },
    init() {
      this.dialog_state = false;
    }
  }
}

</script>
